/* 注册
 * @Author: wujie 
 * @Date: 2018-06-12 11:06:22 
 * @Last Modified by: wujie
 * @Last Modified time: 2018-07-03 16:12:37
 */
import React, { Component } from 'react'
import components from '@/components/index'
import { connect } from 'react-redux'
import actions from '@/actions/register'
import util from '@/utils'

const { RegisterForm } = components

class Register extends Component {

  render() {

    const props = util.pick(this.props, [
      'phoneNum',
      'validateCode',
      'company',
      'name',
      'phoneVadSts',
      'validateCodeEnable',
      'validateCodeCountDown',
      'registerButtonLoading',
    ])

    const funcProps = util.pick(this, [
      'onChangePhoneNum',
      'onChangeValidateCode',
      'onChangeCompany',
      'onChangeName',
      'onGetValidateCode',
      'onAccountLogin',
      'onRegister',
    ])

    return (
      <RegisterForm {...props} {...funcProps} />
    )
  }

  onRegister = () => {
    this.props.register()
  }

  onAccountLogin = () => {
    this.props.history.push('/')
  }

  onGetValidateCode = () => {
    this.props.getValidateCode()
  }

  onChangePhoneNum = ({ target: { value } }) => {
    this.props.setPhoneNum(value)
  }

  onChangeValidateCode = ({ target: { value } }) => {
    this.props.setValidateCode(value)
  }

  onChangeCompany = ({ target: { value } }) => {
    this.props.setCompany(value)
  }

  onChangeName = ({ target: { value } }) => {
    this.props.setName(value)
  }

}

const mapStateToProps = ({ registerReducer }) => ({ ...registerReducer })

export default connect(mapStateToProps, { ...actions })(Register)